package com.wing.work.controller.admin;

import com.wing.cabinet.model.response.EnterpricceIdVO;
import com.wing.cabinet.service.EnterpricceIdService;
import com.wing.common.exception.BusinessException;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.platform.feign.PlatformClient;
import com.wing.user.feign.UserClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author
 */
@Validated
@Api(value = "Admin-售后工单管理", tags = "#/work/saleWorkOrder")
@RestController("saleWorkOrderController")
@RequestMapping("work/admin/saleWorkOrder")
@RequiredArgsConstructor
public class SaleWorkOrderController {

    private final PlatformClient platformClient;

    private final UserClient userClient;

    @Autowired
    private EnterpricceIdService enterpricceIdService;

    @ApiOperation(value = "查询所有反馈工单表", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<com.wing.platform.order.model.entity.WorkOrder> list(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,@RequestParam(value = "wordOrderType") String wordOrderType
            ,@RequestParam(value = "workOrderCode",required = false) String workOrderCode
            ,@RequestParam(value = "productId",required = false) String productId
            ,@RequestParam(value = "moduleId",required = false) String moduleId
            ,@RequestParam(value = "feedbackId",required = false) String feedbackId
            ,@RequestParam(value = "content",required = false) String content
            ,@RequestParam(value = "priority",required = false) String priority
            ,@RequestParam(value = "createTime",required = false) String createTime
            ,@RequestParam(value = "workOrderStatus",required = false) String workOrderStatus
            ,@RequestParam(value = "actualFinishTime",required = false) Long actualFinishTime
            ,@RequestParam(value = "sellId",required = false) String sellId
    ){
        EnterpricceIdVO enterpricceIdVO = enterpricceIdService.getEnterpricceIdVO();
        if(null == enterpricceIdVO){
            throw new BusinessException("请先联系运维人员初始化企业基本信息!");
        }
        Long enterpriseId = Long.valueOf(enterpricceIdVO.getEnterpriseId());
        PageResult<com.wing.platform.order.model.entity.WorkOrder> list = platformClient.getAllWorkOrderList(page, limit, sort, order, wordOrderType,workOrderCode, productId, moduleId, feedbackId, content,
                priority, createTime, workOrderStatus, actualFinishTime,enterpriseId,sellId);
        return new PageResult<>(list.getData(), list.getCount());
    }

    @ApiOperation(value = "获取售后反馈分类", notes = "查询")
    @GetMapping("/getSellOrderCategory")
    public JsonResult getSellOrderCategory(){
        return JsonResult.success(platformClient.getSellOrderCategory());
    }

}
